package com.chenchao.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/18 16:52
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.javathread.Test20.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 线程池
 */
public class Test20 implements Runnable{
    public static void main(String[] args) {
        //创建线程池，工厂模式
        ExecutorService executorService = Executors.newFixedThreadPool(4);
        //添加线程
        executorService.execute(new Test20());
        executorService.execute(new Test20());
        executorService.execute(new Test20());
        executorService.execute(new Test20());
        //关闭线程池
        executorService.shutdown();

    }
    @Override
    public  void run() {
        for (int i = 0; i < 1000;i++) {
            System.out.println(Thread.currentThread().getName()+" "+i+"次运行");

        }
    }
}
